﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BCS.WinFormAppGui
{
        internal static class Program
        {
                /// <summary>
                /// 应用程序的主入口点。
                /// </summary>
                [STAThread]
                private static void Main()
                {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);

                        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                        Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                        Application.Run(new MainForm());
                }

                private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
                {
                        StringBuilder sb = new StringBuilder();
                        Exception ex = e.ExceptionObject as Exception;
                        sb.AppendLine(ex.Message);

                        sb.AppendLine(ex.TargetSite.ToString());
                        sb.AppendLine(ex.Source);
                        sb.AppendLine(ex.StackTrace);

                        MessageBox.Show(sb.ToString());
                }

                private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
                {
                        StringBuilder sb = new StringBuilder();
                        Exception ex = e.Exception;
                        sb.AppendLine(ex.Message);

                        sb.AppendLine(ex.TargetSite.ToString());
                        sb.AppendLine(ex.Source);
                        sb.AppendLine(ex.StackTrace);

                        MessageBox.Show(sb.ToString());
                }
        }
}